define(['app'], function (app) {
app.service('DataService', function () {

	var arr = [];
    this.addItem = function (newItem) {

        var flag = false;
        arr.map(function (item) {
            if (item.id == newItem.id) {
                flag = true;
                item.count++;
            }
        })

        if (flag == false) { 
            newItem.count = 1;
            arr.push(newItem)
        }
    };

    this.reduce = function (index) {
        var item = arr[index];

        if (item.count == 1) {
            arr.splice(index, 1); 
        } else {
            item.count --;
        }
    };

    this.sscsjian = function (newjian) {
    	var flag = false;
        arr.map(function (jian) {
        	console.log(jian);
        	console.log(newjian);
            if (jian.id == newjian.id) {
                flag = true;
                jian.count--;
            }
        })
    }
    this.getAllGoods = function () {
        return arr;
    };
});
})
